<script setup lang="ts">
import {markRaw, onMounted, ref} from "vue";
import type {EChartsOption, EChartsType} from "echarts";
import * as echarts from "echarts";
import {useGetScatterDataApi} from "@/api";
import type {Scatter} from "@/interface";
import 'echarts-wordcloud'

const scatter = ref()
const option = ref<EChartsOption>()
const myChart = ref<EChartsType>()
const scatterData = ref<Scatter>({
  data: []
})
const init = async () => {
  const {data: res} = await useGetScatterDataApi()
  scatterData.value = res
  myChart.value = markRaw(echarts.init(scatter.value));
  draw();
}
const draw = () => {
  option.value = {
    title:{
      text:'专辑数与播放量散点分布图',
      left:'center'
    },
    tooltip:{
      formatter:'{a}<br />{c}'
    },
    xAxis: {
      type:'value'
    },
    yAxis: {
      type:'value'
    },
    series: [
      {
        name:'专辑数,播放量',
        symbolSize: 5,
        data: scatterData.value.data,
        type: 'scatter'
      }
    ]
  }
  myChart.value.setOption(option.value, {notMerge: true});
}
onMounted(() => {
  init()
})
</script>

<template>
  <div ref="scatter" class="scatter">
  </div>
</template>

<style scoped>
.scatter {
  width: 100%;
  height: 100%;
}
</style>